//
//  TouchView.m
//  TeamInformatization
//
//  Created by bigger on 2019/4/1.
//  Copyright © 2019年 SPIC. All rights reserved.
//

#import "TouchView.h"

@implementation TouchView

- (instancetype)initWithFrame:(CGRect)frame TitleText:(NSString *)titleText ImageStr:(NSString *)imageStr
{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
    
        [self creatViewsWithTitleText:titleText ImageStr:imageStr];
    }
    
    return self;
}

- (void)creatViewsWithTitleText:(NSString *)titleText ImageStr:(NSString *)imageStr
{
    UIImageView *showImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageStr]];
    [self addSubview:showImageView];
    [showImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15 * kScaleWidth);
        make.centerY.mas_equalTo(self);
    }];
    
    SimpleLabel *titleTextLabel = [SimpleLabel initWithText:titleText TextColor:kTitleTextColor TextFont:[UIFont fontWithName:@"PingFangSC-Regular" size: 15] TextAlignment:NSTextAlignmentLeft];
    [self addSubview:titleTextLabel];
    [titleTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(showImageView.mas_right).offset(5 * kScaleWidth);
       make.centerY.mas_equalTo(self);
    }];
    
    UIImageView *arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"箭头"]];
    [self addSubview:arrowImageView];
    [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-10 * kScaleWidth);
        make.centerY.mas_equalTo(self);
    }];
    
    SimpleLabel *selectText = [SimpleLabel initWithText:@"请选择" TextColor:kSetRGBColor(153, 153, 153, 1) TextFont:[UIFont fontWithName:@"PingFangSC-Regular" size: 13] TextAlignment:NSTextAlignmentLeft];
    [self addSubview:selectText];
    [selectText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(arrowImageView.mas_left).offset(-5 * kScaleWidth);
        make.centerY.mas_equalTo(self);
    }];
    
    // 分割线
    UILabel *lineLabel = [[UILabel alloc] init];
    lineLabel.backgroundColor = kCuttingLineColor;
    [self addSubview:lineLabel];
    [lineLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(15 * kScaleWidth);
        make.right.mas_equalTo(-10 * kScaleWidth);
        make.height.mas_equalTo(0.5);
    }];
    
    [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchPushAction:)]];
    
}

- (void)touchPushAction:(UITapGestureRecognizer *)rec
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(getTouchwithTouchView:)]) {
        //代理存在且有这个transButIndex:方法
        [self.delegate getTouchwithTouchView:self];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
